package org.sucri.floxs.ext.widget;

import org.sucri.floxs.utils.Json_Util;

import java.util.List;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: Wen Yu
 * Date: Jul 19, 2007
 * Time: 9:34:15 PM
 * To change this template use File | Settings | File Templates.
 */
public class ColumnModel extends ExtWidget
{
  public ColumnModel()           { super(); }
  public ColumnModel(String var) { super(var); }
  
  private Integer mDefaultWidth    = 100;
  private Boolean mDefaultSortable = true;

  public void   addColumn( Column s) { mColumns.add(s); }
  
  private List<Column> mColumns = new ArrayList<Column>();

  @Override
  public String render()
  {
    String cm = "var " + getVarName() + " = " + construct();

    if (mDefaultWidth    != null) cm += getVarName() + ".defaultWidth    = " + mDefaultWidth+ ";" + br();
    if (mDefaultSortable != null) cm += getVarName() + ".defaultSortable = " + (mDefaultSortable ? "true" : "false") + ";" + br();

    return cm;
  }

  /**
   var cm = new Ext.grid.ColumnModel
     ([{
          id: 'title',
          header: "Title",
          dataIndex: 'title',
          width: 250
       },{
          header: "Release Year",
          dataIndex: 'release_year',
          width: 75
       },{
          header: "MPAA Rating",
          dataIndex: 'mpaa',
          width: 75
       },{
          header: "Genre",
          dataIndex: 'genre',
          width: 100
       },{
          header: "Director",
          dataIndex: 'directed_by',
          width: 150
       }]);
   * 
   * @return
   */
  @Override
  public String construct()
  {
    return Json_Util.newJs("Ext.grid.ColumnModel", Json_Util.toJSONString(mColumns, 0));
  }
}
